package com.lagou.filter;

import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;
import redis.clients.jedis.Jedis;

import java.lang.reflect.Method;

/**
 * @ClassName TPMonitorFilter
 * @Description TODO
 * @Auth ying.xiao
 * @Date 2021/4/12
 * @Version 1.0.0
 */
@Activate(group = {CommonConstants.CONSUMER})
public class TPMonitorFilter implements Filter {
    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
        long startTime = System.currentTimeMillis();
        String methodName = invocation.getMethodName();
        // 执行方法
        Result invoke = invoker.invoke(invocation);
        Jedis jedis = JedisPoolUtil.getJedis();
        jedis.setex("TP:" + methodName+startTime, 60,(System.currentTimeMillis() - startTime)+"");
        jedis.close();
        return invoke;
    }
}
